package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.Insert;
import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.annotations.Query;
import com.zhenwei.zscm.common.annotations.Update;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.vo.shipping.ExportVO;
import com.zhenwei.zscm.model.vo.shipping.QueryShippingVO;
import com.zhenwei.zscm.model.vo.shipping.ShippingVO;
import com.zhenwei.zscm.service.ShippingService;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/api/shipping")
@MethodName("发货管理")
public class ShippingController {
    private ShippingService shippingService;

    @MethodName("获取订单编号")
    @GetMapping("/getOrderNumber")
    public RestResult getOrderNumber(){
        return shippingService.getOrderNumber();
    }
    @MethodName("添加订单")
    @PostMapping("/create")
    public RestResult create(@RequestBody @Validated(Insert.class) ShippingVO vo) {
        return shippingService.create(vo);
    }

    @MethodName("修改订单")
    @PostMapping("/update")
    public RestResult update(@RequestBody @Validated(Update.class) ShippingVO vo) {
        return shippingService.update(vo);
    }

    @MethodName("删除订单")
    @GetMapping("/delete")
    public RestResult delete(@RequestParam @NotEmpty(message = "订单ID不能为空") String orderId) {
        return shippingService.delete(orderId);
    }

    @MethodName("获取订单详情")
    @GetMapping("/detail")
    public RestResult detail(@RequestParam @NotEmpty(message = "订单ID不能为空") String orderId) {
        return shippingService.detail(orderId);
    }

    @MethodName("获取发货订单列表")
    @PostMapping("/page")
    public RestResult page(@RequestBody @Validated(Query.class) QueryShippingVO query) {
        return shippingService.page(query);
    }
    @MethodName("获取产品发货日期")
    @GetMapping("/product/shippingDate")
    public RestResult getProductShippingDate(@RequestParam @NotEmpty(message = "产品SN不能为空") String productSn){
        return shippingService.getProductShippingDate(productSn);
    }

    @MethodName("导入发货数据")
    @GetMapping("/import")
    public RestResult importData(@RequestParam @NotEmpty(message = "文件ID不能为空") String fileId) {
        return shippingService.importData(fileId);
    }

    @MethodName("查询最近联系人信息")
    @GetMapping("/getRecentlyContactor")
    public RestResult getRecentlyContactor(@RequestParam @NotEmpty(message = "客户主体不能为空") String purchaseCompanyCode) {
        return shippingService.getRecentlyContactor(purchaseCompanyCode);
    }

    @MethodName("导出发货数据")
    @PostMapping("/export")
    public RestResult export(@RequestBody ExportVO vo) {
        return shippingService.export(vo);
    }
}
